// packagBuy/pages/marketing/verInformation/verInformation.js
import Toast from '../../../../../miniprogram_npm/vant-weapp/toast/toast';
import { couponApi } from '../../../../../config/config'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusHeight,
    username: "",
    phone: "",
    couponId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let couponId = wx.getStorageSync('couponId')
      this.setData({
        couponId: couponId
      })
  },
  goBacke() {
    wx.navigateBack({
      delta: 1,
    })
  },
  userInput(val) {
    this.setData({
      username: val.detail
    })
  },
  phoneInput(val) {
    this.setData({
      phone: val.detail
    })
  },
  submitInfo() {
    let name = this.data.username
    let phone = this.data.phone
    if (!name) {
      Toast('请输入姓名')
    } else if(!phone) {
      Toast('请输入电话')
    } else {
      this.getCode(name, phone)
    }
  },
  getCode(name, phone) {
    let couponId = this.data.couponId
    app.reqFun.requestJson('POST',  couponApi.verification+'?name=' + name + '&phone=' + phone + '&couponId=' + couponId, '', (response) => {
      const res=response.data
      if (res.success == 1) {
        wx.navigateTo({
          url: '/packagBuy/pages/marketing/verifyCoupon/verInforCode/verInforCode?name=' + name + '&phone=' + phone + '&couponId=' + couponId,
        })
      }else{
        wx.showToast({
          title:res.msg || '用户信息有误',
          icon: 'none',   // 图标类型，默认success
          duration: 1500   // 提示窗停留时间，默认1500ms
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 禁用用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})